$(function() {
	
	jQuery(document).ready(function () {
		getShopInfo();
	});
	
	function getShopInfo(){
		var id = jQuery('#shopId').val();
		 var url=window.rootPath+"/ui/index/getShowInfo/"+id;
         jQuery.ajax({
             url:encodeURI(url),
             cache:false,
             type : "get",
             dataType:"json",
             success:function(result){
            	  	var data = result.shop;
				$('#stardiv').raty();
				if (result.evaluate != undefined) {
					$('#stardiv').raty({
						number : 5,
						readOnly : true,
						size:$("#divstar").attr("width")-5,
						score : result.evaluate.evaluateScale / 20.0
					});
				} else {
					$('#stardiv').raty({
						number : 5,
						size:$("#divstar").attr("width")-5,
						readOnly : true,
						score : 0
					});
				}
				
				var avatarUrl=data.pictureAdress;
				if(avatarUrl==undefined||avatarUrl==""){
					avatarUrl="../img/nopicture.png";
				}else{
					avatarUrl=window.rootPath+'/'+avatarUrl;
				}
				jQuery("#iconAddress").prop("src", avatarUrl);

				$("#shopName").val(data.shopName);
				if (data.infoState != undefined) {
					var path = "";
					if (data.infoState.title == '待认证') {
						path = "../../../img/authentication_in.png";
					} else if (data.infoState.title == '认证拒绝') {
						path = "../../../img/authentication_notaccess.png";
					} else if (data.infoState.title == '认证通过') {
						path = "../../../img/authentication_access.png";
					} else if (data.infoState.title == '初始化') {
						path = "../../../img/authentication_init.png";
					} else if (data.infoState.title == null) {
						path = "";
					}
					$("#infoState").attr('src', path);
				}

				$("#shopAdress").val(data.shopAdress);
				$("#areaMeasure").val(data.areaMeasure+" 平方米");
				$("#signPerson").val(data.signPerson);
				$("#signPersonPhone").val(data.signPersonPhone);
				$("#cleaningPerson").val(data.cleaningPerson);
				$("#cleaningPersonPhone").val(data.cleaningPersonPhone);
				$("#managementRange").val(data.managementRange);
				$("#memo").val(data.memo);
				if (data.bussinessLevel.userName!=null) {
					$('#areaMperson').html(data.bussinessLevel.userName);
				}
				
				var InspectionHistory = result.InspectionHistory;
				InspectionHtml(InspectionHistory,$('#InspectionHistory'));
				var Inspection = result.Inspection;
				InspectionHtml(Inspection,$('#Inspection'));

				var CheckHistory = result.CheckHistory;
				CheckHtml(CheckHistory,$('#CheckHistory'));
			}
         });
         
         function InspectionHtml(data, obj){
        	 	var html = '';
			for(var i=0;i<data.length;i++){
				var temp = data[i];
				html += '<tr><td>'+moment(temp.inspectDate).format('YYYY/MM/DD')+'</td><td>'+temp.user.name+'</td><td>'+temp.inspectCondition.title+'</td></tr>';
			}
			obj.html(html);
         }

         function CheckHtml(data, obj){
	        	 var html = '';
	        	 for(var i=0;i<data.length;i++){
	        		 var temp = data[i];
	        		 html += '<tr><td>'+moment(temp.checkDate).format('YYYY/MM/DD')+'</td><td>'+temp.user.name+'</td><td>'+temp.checkCondition+'</td><td>'+temp.rectifyCondition+'</td><td>'+temp.remark+'</td></tr>';
	        	 }
	        	 obj.html(html);
         }
	}
	
	//将度转换成为度分秒
	function longFormatDegree(value) {
		var long ='E';
		if(value < 0){
			long = 'W'
		}
        value = Math.abs(value);
        var v1 = Math.floor(value);//度
        var v2 = Math.floor((value - v1) * 60);//分
        var v3 = ((value - v1) * 3600 % 60).toFixed(2);//秒
        return long + v1 + '°' + v2 + '\'' + v3 + '"';
    };
    
    function latFormatDegree(value) {
    		var lat ='N';
		if(value < 0){
			lat = 'S'
		}
	    	value = Math.abs(value);
	    	var v1 = Math.floor(value);//度
	    	var v2 = Math.floor((value - v1) * 60);//分
	    	var v3 = ((value - v1) * 3600 % 60).toFixed(2);//秒
	    	return lat + v1 + '°' + v2 + '\'' + v3 + '"';
    };
});
